import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
  path: '/redirect',
  component: Layout,
  hidden: true,
  children: [{
    path: '/redirect/:path(.*)',
    component: () =>
      import ('@/views/redirect/index')
  }]
},
{
  path: '/login',
  component: () =>
    import ('@/views/login/index'),
  hidden: true
},
{
  path: '/404',
  component: () =>
    import ('@/views/error-page/404'),
  hidden: true
},
{
  path: '/401',
  component: () =>
    import ('@/views/error-page/401'),
  hidden: true
},
{
  path: '/',
  component: Layout,
  redirect: 'index',
  name: 'home',
  meta: {
    icon: 'el-icon-s-tools'
  },
  children: [{
    path: '/index',
    component: () =>
      import ('@/views/home/index'),
    name: 'homeIndex',
    meta: {
      title: '首页'
    }
  }]
},
// {
// 	path: '/addroles',
// 	component: () => import('@/views/tal-admin/permission/addroles'),
// 	name: 'addroles',
// 	meta: {
// 		title: '隐藏添加路由的页面，请勿删除'
// 	},
// 	hidden: true
// },
{
  path: '/member',
  component: Layout,
  redirect: 'list',
  name: 'memberManage',
  meta: {
    title: '会员管理',
    icon: 'el-icon-s-tools',
    roles: ['admin', 'editor']
  },
  children: [{
    path: 'list',
    component: () =>
      import ('@/views/member/list'),
    name: 'memberList',
    meta: {
      title: '会员列表'
    }
  },
  {
    path: 'detail/:id',
    component: () =>
      import ('@/views/member/detail'),
    name: 'memberDetail',
    meta: {
      title: '会员详情',
      activeMenu: '/member/list'
    },
    hidden: true
  },
  {
    path: 'subordinate/:id',
    component: () =>
      import ('@/views/member/subordinate'),
    name: 'memberSubordinate',
    meta: {
      title: '查看下级',
      activeMenu: '/member/list'
    },
    hidden: true
  },
  {
    path: 'whiteList',
    component: () =>
      import ('@/views/member/whiteList'),
    name: 'memberWhiteList',
    meta: {
      title: '白名单'
    }
  }
  ]
},
{
  path: '/auction-good',
  component: Layout,
  // redirect: "preview",
  redirect: 'classify',
  name: 'auctionGoodManage',
  meta: {
    title: '拍品管理',
    icon: 'el-icon-s-tools',
    roles: ['admin', 'editor']
  },
  children: [
    //   {
    //     path: "preview",
    //     component: () => import("@/views/auctionGood/preview"),
    //     name: "auctionGoodPreview",
    //     meta: {
    //       title: "拍品概览"
    //     }
    //   },
    {
      path: 'classify',
      component: () =>
        import ('@/views/auctionGood/classify'),
      name: 'auctionGoodClassify',
      meta: {
        title: '拍品分类'
      }
    },
    {
      path: 'examine',
      component: () =>
        import ('@/views/auctionGood/examine'),
      name: 'auctionGoodExamine',
      meta: {
        title: '上传审核'
      }
    },
    {
      path: 'wait',
      component: () =>
        import ('@/views/auctionGood/wait'),
      name: 'auctionGoodWait',
      meta: {
        title: '商品列表'
      }
    },
    {
      path: 'exhibition',
      component: () =>
        import ('@/views/auctionGood/exhibition'),
      name: 'auctionGoodExhibition',
      meta: {
        title: '上拍审核'
      }
    },
    {
      path: 'list',
      component: () =>
        import ('@/views/auctionGood/list'),
      name: 'auctionGoodList',
      meta: {
        title: '拍品列表'
      }
    },
    {
      path: 'haspickup',
      component: () =>
        import ('@/views/auctionGood/haspickup'),
      name: 'auctionGoodHaspickup',
      meta: {
        title: '已提货'
      }
    },
    {
      path: 'successful',
      component: () =>
        import ('@/views/auctionGood/successful'),
      name: 'auctionGoodSuccessful',
      meta: {
        title: '成交记录'
      }
    },
    {
      path: 'log',
      component: () =>
        import ('@/views/auctionGood/log'),
      name: 'auctionGoodLog',
      meta: {
        title: '操作日志'
      }
    }
  ]
},
{
  path: '/auctioning',
  component: Layout,
  redirect: 'preview',
  name: 'auctioningManage',
  meta: {
    title: '拍卖管理',
    icon: 'el-icon-s-tools',
    roles: ['admin', 'editor']
  },
  children: [{
    path: 'preview',
    component: () =>
      import ('@/views/auctioning/preview'),
    name: 'auctioningPreview',
    meta: {
      title: '拍卖预览'
    }
  },
  {
    path: 'manage',
    component: () =>
      import ('@/views/auctioning/manage'),
    name: 'auctioningManages',
    meta: {
      title: '拍卖管理'
    }
  },
  {
    path: 'bid-record',
    component: () =>
      import ('@/views/auctioning/bidRecord'),
    name: 'auctioningBidRecord',
    meta: {
      title: '出价记录'
    }
  },
  {
    path: 'subscribe-record',
    component: () =>
      import ('@/views/auctioning/subscribeRecord'),
    name: 'auctioningSubscribeRecord',
    meta: {
      title: '预约记录'
    }
  }
  ]
},
{
  path: '/orders',
  component: Layout,
  redirect: 'waitpay',
  name: 'ordersManage',
  meta: {
    title: '订单管理',
    icon: 'el-icon-s-tools',
    roles: ['admin', 'editor']
  },
  children: [{
    path: 'waitpay',
    component: () =>
      import ('@/views/orders/wait-pay'),
    name: 'waitPay',
    meta: {
      title: '待付款'
    }
  },
  {
    path: 'waitdelivery',
    component: () =>
      import ('@/views/orders/wait-delivery'),
    name: 'waitDelivery',
    meta: {
      title: '待提货/续拍'
    }
  },
  {
    path: 'continue',
    component: () =>
      import ('@/views/orders/continue'),
    name: 'ordersContinue',
    meta: {
      title: '续拍订单'
    }
  },
  {
    path: 'detail-sc/:id',
    component: () =>
      import ('@/views/orders/detail-sc'),
    name: 'ordersDetailSc',
    meta: {
      title: '详情-首次上传商品',
      activeMenu: '/orders/continue'
    },
    hidden: true
  },
  {
    path: 'pickupmj',
    component: () =>
      import ('@/views/orders/pick-up-mj'),
    name: 'pickUpMj',
    meta: {
      title: '买家提货'
    }
  },
  {
    path: 'pickuppt',
    component: () =>
      import ('@/views/orders/pick-up-pt'),
    name: 'pickUpPt',
    meta: {
      title: '平台提货'
    }
  },
  {
    path: 'shippt',
    component: () =>
      import ('@/views/orders/ship-pt'),
    name: 'shipPt',
    meta: {
      title: '平台发货'
    }
  },
  //   {
  //     path: "delivery",
  //     component: () => import("@/views/orders/delivery"),
  //     name: "ordersDelivery",
  //     meta: {
  //       title: "提货订单"
  //     }
  //   },
  {
    path: 'detail-th/:id',
    component: () =>
      import ('@/views/orders/detail-th'),
    name: 'ordersDetailTh',
    meta: {
      title: '提货订单详情',
      activeMenu: '/orders/delivery'
    },
    hidden: true
  },
  {
    path: 'after-sale',
    component: () =>
      import ('@/views/orders/afterSale'),
    name: 'ordersAfterSale',
    meta: {
      title: '售后管理'
    }
  }
  ]
},
{
  path: '/merchants',
  component: Layout,
  redirect: 'manage',
  name: 'merchantsManage',
  meta: {
    title: '多商户',
    icon: 'el-icon-s-tools',
    roles: ['admin', 'editor']
  },
  children: [{
    path: 'manage',
    component: () =>
      import ('@/views/merchants/manage'),
    name: 'merchantsManages',
    meta: {
      title: '商户管理'
    }
  },
  {
    path: 'request',
    component: () =>
      import ('@/views/merchants/request'),
    name: 'merchantsRequest',
    meta: {
      title: '商户入驻申请'
    }
  },
  {
    path: 'info/:id',
    component: () =>
      import ('@/views/merchants/info'),
    name: 'merchantsInfo',
    meta: {
      title: '商户信息'
    },
    hidden: true
  },
  {
    path: 'deposit',
    component: () =>
      import ('@/views/merchants/deposit'),
    name: 'merchantsDeposit',
    meta: {
      title: '店铺保证金记录'
    }
  }
    //   {
    //     path: "payment",
    //     component: () => import("@/views/merchants/payment"),
    //     name: "merchantsPayment",
    //     meta: {
    //       title: "结算记录"
    //     }
    //   }
  ]
},
{
  path: '/distributions',
  component: Layout,
  redirect: 'list',
  name: 'distributionsShop',
  meta: {
    title: '分销小店',
    icon: 'el-icon-s-tools',
    roles: ['admin', 'editor']
  },
  children: [{
    path: 'list',
    component: () =>
      import ('@/views/distributions/list'),
    name: 'distributionsList',
    meta: {
      title: '小店列表'
    }
  },
  {
    path: 'examine',
    component: () =>
      import ('@/views/distributions/examine'),
    name: 'distributionsExamine',
    meta: {
      title: '待审核小店'
    }
  },
  {
    path: 'deposit',
    component: () =>
      import ('@/views/distributions/deposit'),
    name: 'distributionsDeposit',
    meta: {
      title: '保证金记录'
    }
  }
    //   {
    //     path: "cash-out",
    //     component: () => import("@/views/distributions/cashOut"),
    //     name: "distributionsCashOut",
    //     meta: {
    //       title: "结算记录"
    //     }
    //   }
  ]
},
{
  path: '/distributions-manage',
  component: Layout,
  redirect: 'recommend-orders',
  name: 'distributionsManage',
  meta: {
    title: '分销管理',
    icon: 'el-icon-s-tools',
    roles: ['admin', 'editor']
  },
  children: [{
    path: 'recommend-orders',
    component: () =>
      import ('@/views/distributionsManage/recommendOrders'),
    name: 'distributionsManageOrders',
    meta: {
      title: '推荐订单'
    }
  },
  {
    path: 'detail-fx/:id',
    component: () =>
      import ('@/views/distributionsManage/detail-fx'),
    name: 'distributionsManageDetailFx',
    meta: {
      title: '详情-分销商品',
      activeMenu: '/distributions-manage/recommend-orders'
    },
    hidden: true
  },
  {
    path: 'hire-cost',
    component: () =>
      import ('@/views/distributionsManage/hireCost'),
    name: 'distributionsManageHireCost',
    meta: {
      title: '佣金结算记录'
    }
  }
  ]
},
{
  path: '/finance',
  component: Layout,
  redirect: 'supplement',
  name: 'financeManage',
  meta: {
    title: '财务管理',
    icon: 'el-icon-s-tools',
    roles: ['admin', 'editor']
  },
  children: [{
    path: 'supplement',
    component: () =>
      import ('@/views/finance/supplement'),
    name: 'financeSupplement',
    meta: {
      title: '充值记录'
    }
  },
  {
    path: 'refund',
    component: () =>
      import ('@/views/finance/refund'),
    name: 'financeRefund',
    meta: {
      title: '退款记录'
    }
  },
  {
    path: 'bond-cash-out',
    component: () =>
      import ('@/views/finance/bondCashOut'),
    name: 'financeBondCashOut',
    meta: {
      title: '店铺保证金提现'
    }
  },
  {
    path: 'wallet-cash-out',
    component: () =>
      import ('@/views/finance/walletCashOut'),
    name: 'financeWalletCashOut',
    meta: {
      title: '钱包提现'
    }
  },

  {
    path: 'shop-check-out',
    component: () =>
      import ('@/views/finance/shopCheckOut'),
    name: 'financeShopCheckOut',
    meta: {
      title: '店铺结算'
    }
  },
  {
    path: 'buyers-deposit',
    component: () =>
      import ('@/views/finance/buyersDeposit'),
    name: 'financeBuyersDeposit',
    meta: {
      title: '买家保证金'
    }
  },
  {
    path: 'wallet-details',
    component: () =>
      import ('@/views/finance/WalletDetails'),
    name: 'walletDetails',
    meta: {
      title: '钱包明细'
    }
  }
  ]
},
{
  path: '/setting',
  component: Layout,
  redirect: 'basics',
  name: 'settingManage',
  meta: {
    title: '基础设置',
    icon: 'el-icon-s-tools',
    roles: ['admin', 'editor']
  },
  children: [{
    path: 'basics',
    component: () =>
      import ('@/views/setting/basics'),
    name: 'settingBasics',
    meta: {
      title: '基础设置'
    }
  },
  {
    path: 'photo',
    component: () =>
      import ('@/views/setting/photo'),
    name: 'settingPhoto',
    meta: {
      title: '图片管理器'
    }
  },
  {
    path: 'carousel',
    component: () =>
      import ('@/views/setting/carousel'),
    name: 'settingCarousel',
    meta: {
      title: '轮播图管理'
    }
  },
  {
    path: 'address',
    component: () =>
      import ('@/views/setting/address'),
    name: 'settingAddress',
    meta: {
      title: '平台收货地址'
    }
  },
  {
    path: 'notice',
    component: () =>
      import ('@/views/setting/notice'),
    name: 'settingNotice',
    meta: {
      title: '公告配置'
    }
  }
  ]
},
{
  path: '/article',
  component: Layout,
  redirect: 'list',
  name: 'articleManage',
  meta: {
    title: '文章管理',
    icon: 'el-icon-s-tools',
    roles: ['admin', 'editor']
  },
  alwaysShow: true,
  children: [{
    path: 'list',
    component: () =>
      import ('@/views/article/list'),
    name: 'articleList',
    meta: {
      title: '文章列表'
    }
  }]
},
{
  path: '/total',
  component: Layout,
  redirect: 'business',
  name: 'totalManage',
  meta: {
    title: '数据统计',
    icon: 'el-icon-s-tools',
    roles: ['admin', 'editor']
  },
  alwaysShow: true,
  children: [{
    path: 'business',
    component: () =>
      import ('@/views/total/business'),
    name: 'totalBusiness',
    meta: {
      title: '交易统计'
    }
  }]
}
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({
      y: 0
    }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
